import { tableOption } from './buyingIfor.config.js'
import { toDecimal2 } from '@/utils/util'
export default {
    name: "buyingIfor",
    props: {
        loadData: {
            type: Array,
            default: []
        },
        price: {
            type: Number,
            default: 0
        },
    },
    data() {
        return {
            tableOption,
            loading: false,
            activeNames: '1',
            btn: [
                // {
                //     title: "选择商品",
                //     isShow: true,

                // },
            ],
            // total: {
            //     number: 0, //商品数量
            //     price: 0 //总价格
            // },
            dataList: [{}],
            _index1: 0,
            toDecimal2:toDecimal2
        }
    },
    methods: {
        onConversionNumChange:function(e){

            this.dataList.forEach(ele=>{
                ele.shopPurchaseGoodsList.forEach(good=>{

                    console.log('good',good)
                    //计算转换数量
                    good.goodsNum = good.conversionNum*good.convertUnitNum;

                    //计算小计
                    good.goodSubtotal = good.goodsNum*good.costPrice;
                })
            })
            this.cacaulateSum();
        },
        //计算商品数量 和总计金额
        cacaulateSum(){
            var sumAmt = 0
            this.dataList.forEach(ele=>{
                ele.shopPurchaseGoodsList.forEach(good=>{
                sumAmt+=good.goodSubtotal;    
                })
            })
            this.total.price = sumAmt
            this.total.number   = this.dataList[this._index1].shopPurchaseGoodsList.length
        }
    }

} 